<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 文章管理 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
</head>
<style>
    .layui-form-label {
        width: 120px;
    }
</style>
<body>
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <input type="hidden" name="id" value="{$find.id}">
    <input type="hidden" name="pid" value="{$pro.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">活动名称</label>
        <div class="layui-input-inline" style="width: 375px;">
            <input type="text" name="name" value="{$find.name ?? $pro.name}" lay-verify="required" placeholder="活动名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">原价</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="original_cost" value="{$find.original_cost ?? $pro.original_cost}" lay-verify="required|number" placeholder="原价" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">返现余额</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="back_cost" value="{$find.back_cost ?? 0}" lay-verify="required|number" placeholder="返现余额" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">活动状态</label>
        <div class="layui-input-inline" style="width: 100px;">
            <input type="checkbox" name="status" value="1" lay-skin="switch" lay-text="开启|关闭" {if condition="$find eq ''"}checked{/if}{eq name="find.status" value="1"}checked{/eq}>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>
<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$,
                form = layui.form,
                laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#test'
            ,type: 'datetime'
            ,range: true
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                type: "POST",
                url: "{:url('Market/back_add')}",
                data: {field:field},
                dataType: "json",
                success: function(e){
                    if (e.code == 200){
                        layer.msg(e.data);
                        setTimeout(function () {
                            parent.layer.close(index); //再执行关闭
                            parent.layui.index.openTabsPage('/admin/Market/back', '全返活动');
                        }, 500)
                    }else{
                        layer.msg(e.msg);
                    }
                }
            });
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-edit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                type: "POST",
                url: "{:url('Market/back_edit')}",
                data: {field:field},
                dataType: "json",
                success: function(e){
                    if (e.code == 200){
                        layer.msg(e.data);
                        setTimeout(function () {
                            open_window.layui.table.reload('demo'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        }, 500)
                    }else{
                        layer.msg(e.msg);
                    }
                }
            });
        });
    })

    var open_window;
    function child(d) {
        open_window = d;
    }
</script>
</body>
</html>